#include "StdAfx.h"
#include "Vector2.h"

VAMPIRE_NAMESPACE_BEGIN

Vector2::Vector2( const Real& x, const Real& y )
{
	mData.x = x;
	mData.y = y;
}

Vector2 Vector2::operator+( const Vector2& rhs ) const
{
	return Vector2(mData + rhs.mData);
}

Vector2 Vector2::operator+() const
{
	return *this;
}

Vector2 Vector2::operator-( const Vector2& rhs ) const
{
	return Vector2(mData - rhs.mData);
}

Vector2 Vector2::operator*( const Real& rhs ) const
{
	return Vector2(mData * rhs);
}	

Real Vector2::operator*( const Vector2& rhs ) const
{
	return D3DXVec2Dot(&mData, &(rhs.mData));
}

Vector2 Vector2::operator/( const Real& rhs ) const
{
	return Vector2(mData / rhs);
}

Vector2& Vector2::operator+=( const Vector2& rhs )
{
	mData += rhs.mData;
	return *this;
}

Vector2& Vector2::operator-=( const Vector2& rhs )
{
	mData -= rhs.mData;
	return *this;
}

Vector2& Vector2::operator*=( const Real& rhs )
{
	mData *= rhs;
	return *this;
}

Vector2& Vector2::operator/=( const Real& rhs )
{
	mData /= rhs;
	return *this;
}

void Vector2::operator=( const Vector2& rhs )
{
	mData = rhs.mData;
}

void Vector2::operator=( const D3DXVECTOR2& rhs )
{
	mData = rhs;
}

bool Vector2::operator==( const Vector2& rhs ) const
{
	return mData == rhs.mData ? true : false;
}

bool Vector2::operator!=( const Vector2& rhs ) const
{
	return mData == rhs.mData ? false : true;
}

Vector2 Vector2::operator-() const
{
	return Vector2(-mData);
}

Vector2 Vector2::add( const Vector2& other ) const
{
	Vector2 sum;
	D3DXVec2Add(&(sum.mData), &mData, &(other.mData));
	return sum;
}

Real Vector2::cross( const Vector2& rhs ) const
{
	return D3DXVec2CCW(&mData, &(rhs.mData));
}

Vampire::Real Vector2::dot( const Vector2& rhs ) const
{
	return D3DXVec2Dot(&mData, &(rhs.mData));
}

Real Vector2::length() const
{
	return D3DXVec2Length(&mData);
}

Vampire::Real Vector2::lengthSqrt() const
{
	return D3DXVec2LengthSq(&mData);
}

void Vector2::normalise()
{
	D3DXVec2Normalize(&mData, &mData);
}

void Vector2::scale( const Real& s )
{
	D3DXVec2Scale(&mData, &mData, s);
}

Vector2 Vector2::subtract( const Vector2& other ) const
{
	Vector2 difference;
	D3DXVec2Subtract(&(difference.mData), &mData, &(other.mData));
	return difference;
}

void Vector2::transformCoord( const Matrix44& matrix )
{
	D3DXVec2TransformCoord(&mData, &mData, &(matrix.mData));
}

void Vector2::transformNormal( const Matrix44& matrix )
{
	D3DXVec2TransformNormal(&mData, &mData, &(matrix.mData));
}

const Vector2 Vector2::UNIT_X(1.0f, 0.0f);
const Vector2 Vector2::UNIT_Y(0.0f, 1.0f);

const Vector2 Vector2::NEGATIVE_UNIT_X(-1.0f, 0.0f);
const Vector2 Vector2::NEGATIVE_UNIT_Y(0.0f, -1.0f);

const Vector2 Vector2::ZERO(0.0f, 0.0f);

VAMPIRE_NAMESPACE_END